package com.lwt.db137.service.Impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lwt.db137.bean.RoleMenu;
import com.lwt.db137.mapper.RolemenuMapper;
import com.lwt.db137.service.RolemenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description  
 * @version 1.0 
 * @author lwt
 * @date 2024/12/24 11:48
 */
@Service
public class RolemenuServiceImpl extends ServiceImpl<RolemenuMapper, RoleMenu> implements RolemenuService {
    @Autowired
    private RolemenuMapper rolemenuMapper;

    @Override
    public boolean  updateRoleMenu(int roleid, List<Integer> menuids) {
        //删除该角色原有的菜单
        UpdateWrapper<RoleMenu> UpdateWrapper = new UpdateWrapper<>();
        UpdateWrapper.eq("roleid",roleid);
        System.out.println("UpdateWrapper = " + UpdateWrapper);
        rolemenuMapper.delete(UpdateWrapper);
        for (Integer menuid : menuids) {
            RoleMenu roleMenu = new RoleMenu();
            roleMenu.setRoleid(roleid);
            roleMenu.setMenuid(menuid);
            rolemenuMapper.insert(roleMenu);
        }
        return true;
        //根据角色id添加对应的菜单
    }
}
